/******************************************************************************
*  COPYRIGHT MorningCore CO.,LTD
******************************************************************************/

/*----------- function definition-----------------------------------*/
/*****************************************************************************
* Function: ue_tx_pusch_mod_fix()
* Purpose:  This function performs pusch's modulation
*
* Relation:
Calls       : ....
Called by   : ....
* Params:
*   <Name>          <Type>      <In/Out>    <Description>
 P_DataIp[95040]    int8          In        input binary bit after scrambling
 PUSCH_RB_Num       int8          In        RB number of PUSCH
 PUSCH_SymNum       int8          In        number of SC-FDMA symbols for PUSCH
 ModuMod            int8          In        modulation mode
 DataOp[12][1320]   cmplx_frN     Out       output of modulation

* Return:  void
* Note:    <no>
*******************************************************************************/
#include "../head/ue_tx_pusch_mod_fix.h"
//#define _CRT_SECURE_NO_DEPRECATE
/******************************************************************************
*  INCLUDE FILES
******************************************************************************/
void PUSCH_QAMModu_fix
(
    IN int8 P_DataIp[],//input binary bit after scrambling
    IN stULParamTable *SimParam,
    OUT cmplx_frN   DataOp[]//output of modulation
)
{
    /*variables definition*/
    int32 k, Symb_Num = SimParam->QAM_SymNum[SimParam->CW_Idx];     //for cycle
    fractN  Real, Imag;
    int8 modmod = 0, ModuMod = SimParam->ModuMod[SimParam->CW_Idx]; //
    fractN  BPSK_Table[4][2] = {{1, 1}, {-1, 1}, {-1, -1}, {1, -1}};
    int8 BPSK_Table_idx = 0;
    /*Init*/

    /*Function body*/
    if (ModuMod == 0) //QPSK
    {
        modmod = BPSK;
    }
    else if (ModuMod == 1) //QPSK
    {
        modmod = QPSK;
    }
    else if (ModuMod == 2) //QAM16
    {
        modmod = QAM16;
    }
    else if (ModuMod == 3) //QAM64
    {
        modmod = QAM64;
    }
    else
    {
        printf("Error SimParam->ModuMod[SimParam->CW_Idx] Config!\n");
    }

    if (modmod == BPSK)   //
    {
        BPSK_Table_idx = 0;
        for (k = 0; k < Symb_Num; k++)
        {
            DataOp[k].re = (fractN)((1 - 2 * P_DataIp[k]) * BPSK_Table[BPSK_Table_idx][0]);
            DataOp[k].im = (fractN)((1 - 2 * P_DataIp[k]) * BPSK_Table[BPSK_Table_idx][1]);

            BPSK_Table_idx = (BPSK_Table_idx + 1) % 2;
        }
    }
    if (modmod == QPSK)   //
    {
        for (k = 0; k < Symb_Num; k++)
        {
            DataOp[k].re = (fractN)(1 - 2 * P_DataIp[2 * k]);
            DataOp[k].im = (fractN)(1 - 2 * P_DataIp[2 * k + 1]);
        }

    }               //end of QPSK modulation
    if (modmod == QAM16)   //
    {
        for (k = 0; k < Symb_Num; k++)
        {
            DataOp[k].re = (fractN)((1 - 2 * P_DataIp[4 * k]) * (1 + 2 * P_DataIp[4 * k + 2]));
            DataOp[k].im = (fractN)((1 - 2 * P_DataIp[4 * k + 1]) * (1 + 2 * P_DataIp[4 * k + 3]));

        }
    }               //end of QAM16 modulation
    if (modmod == QAM64)   //
    {

        for (k = 0; k < Symb_Num; k++)
        {
            Real = (fractN)(3 - 2 * P_DataIp[6 * k + 4]);
            Imag = (fractN)(3 - 2 * P_DataIp[6 * k + 5]);
            if (P_DataIp[6 * k + 2])
            {
                Real = 8 - Real;
            }
            if (P_DataIp[6 * k + 3])
            {
                Imag = 8 - Imag;
            }
            DataOp[k].re = (1 - 2 * P_DataIp[6 * k]) * Real;
            DataOp[k].im = (1 - 2 * P_DataIp[6 * k + 1]) * Imag;
        }
    }               //end of QAM64 modulation

}
